package org.framework.orm.mysql;

import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public abstract class AbstractMysqlDao<T> extends SqlSessionDaoSupport implements ApplicationContextAware {

    ApplicationContext applicationContext;
    @Override
    public void setApplicationContext(ApplicationContext var1){
        applicationContext = var1;
    }

    public T one(){
        final MysqlMapper<T> mapper = (MysqlMapper)this.getSqlSession().getMapper(this.mapperClass());
        T t = mapper.one();
        return t;
    }
    protected void checkDaoConfig() {
//        String template = this.template();
        SqlSessionTemplate sqlSessionTemplate;
//        if (StringUtils.isNotBlank(template)) {
//            sqlSessionTemplate = (SqlSessionTemplate)this.applicationContext.getBean(template);
//            this.setSqlSessionTemplate(sqlSessionTemplate);
//        } else {
            sqlSessionTemplate = (SqlSessionTemplate)this.applicationContext.getBean(SqlSessionTemplate.class);
            this.setSqlSessionTemplate(sqlSessionTemplate);
//        }

//        DBSql.register(this);
        super.checkDaoConfig();
    }
    protected abstract Class mapperClass();
}
